package com.longcai.controller.admin;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.longcai.bean.ApiResult;
import com.longcai.bean.PageHelper;
import com.longcai.entity.order.ClyjGoodsOrderDetails;
import com.longcai.page.table.PageTableResponse;
import com.longcai.service.ClyjGoodsOrderDetailsService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletRequest;
import java.util.Map;

/**
 * @author Administrator
 * @Title: ClyjGoodsOrderDetailsAdminController
 * @ProjectName clyj-electricity
 * @Description: TODO
 * @date 2019/4/2915:26
 */
@RestController
@RequestMapping(value = "/goodsOrderDetails/")
public class ClyjGoodsOrderDetailsAdminController {

    @Autowired
    private ClyjGoodsOrderDetailsService clyjGoodsOrderDetailsService;


    /**
     * 根据商铺id查询所有订单
     *
     * @param params
     * @return
     */
    @RequestMapping(value = "selectOrderByShopsId")
    @ResponseBody
    public PageTableResponse selectOrderByShopsId(@RequestBody JSONObject params, @RequestBody PageHelper pageHelper) {
        return this.clyjGoodsOrderDetailsService.selectByShopsId(params, pageHelper);
    }

    /**
     *  查询订单列表（auth跨服务调用）
     * @param map
     * @return
     */
    @RequestMapping(value = "selectOrderList")
    @ResponseBody
    public PageTableResponse selectOrderList(@RequestBody Map<String,Object> map) {
        JSONObject params = (JSONObject)JSONObject.toJSON(map.get("params")) ;
        JSONObject jsonPage = (JSONObject)JSONObject.toJSON(map.get("pageHelper"));
        PageHelper pageHelper = JSON.toJavaObject(jsonPage,PageHelper.class);
        return this.clyjGoodsOrderDetailsService.selectByShopsId(params, pageHelper);
    }

    /**
     * 根据订单号查询订单详情
     *
     * @param
     * @return
     */
    @RequestMapping(value = "selectOrderByTradeNo")
    public ApiResult<?> selectOrderByTradeNo(String tradeNo) {
        return this.clyjGoodsOrderDetailsService.selectOrderBytradeNo(tradeNo);
    }

    @RequestMapping(value = "updateOrderInfo")
    public ApiResult<?> updateOrderInfo(@RequestBody Map<String,Object> map) {
        return this.clyjGoodsOrderDetailsService.updateOrderInfo(map);
    }
}